package net.shenru.encogs;

import net.shenru.os.task.TaskStatue;

/**
 * 爬虫的基类
 */
public abstract class Encog {

	private long id;
	private TaskStatue statue;
	private int progress;
	private EncogType type;
	private EncogListener listener;
	protected EncogTask task;
	// 爬虫有id
	// 爬虫有状态 准备 运行 停止
	// 爬虫有类型
	// 爬虫有结果
	// 爬虫有工作进度

	public void setEncogListener(EncogListener listener) {
		this.listener = listener;
	}

	public void run() {
		if (listener != null) {
			listener.onEncogStart(this);
		}
		
		onEncog();
		end();
	}

	public abstract void onEncog();

	public void end() {
		if (listener != null) {
			listener.onEncogEnd(this);
		}
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public TaskStatue getStatue() {
		return statue;
	}

	public void setStatue(TaskStatue statue) {
		this.statue = statue;
	}

	public int getProgress() {
		return progress;
	}

	public void setProgress(int progress) {
		this.progress = progress;
	}

	public EncogType getType() {
		return type;
	}

	public void setType(EncogType type) {
		this.type = type;
	}

	public void setTask(EncogTask task) {
		this.task = task;
	}
	
	public EncogTask getTask(){
		return task;
	}

}
